package batch.home;

import javax.xml.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.*;

import java.util.Vector;
import java.util.Properties;
import java.io.*;
import java.net.*;

import batch.common.report.*;

public class makeHomeForTur
{
    final String strJavaName = "TUR makeHomeForTur";
    final int    ILENG       = 5;

    private final String TODAY              = DateFormatUtils.format(new Date(), "yyyyMMdd");  //Get Current Date
    private final String IMAGE_URL_MAIN     = "/images/main/";
    private final String MAILSUBJECT        = "TUR HOME Batch Error(" + TODAY + ")";
    private final String FILE_PATH          = "/home01/sfc/batch/home/data/tur_home/" + TODAY;
    private final String STR_URL            = "http://www.samsungmobile.com.tr/link/goPremium.jsp?";
    private final String IMAGE_URL_RINGTONE = "/images/funclub/main/";
    private final String IMAGE_URL_GAME     = "/images/funclub/main/";
    private final String IMAGE_URL_IMAGE    = "/images/funclub/main/";

    String strContentName = "";
    String strPreviewUrl = "";
    String strContentID = "";
    String strUrl = "";

    private StringBuffer sHtml = new StringBuffer();

    public makeHomeForTur(){
        init();
    }

    public void init(){
        BufferedReader bfrString = null;
        StringBuffer sbfXml = new StringBuffer();

        Document doc = null;
        NodeList nlTemp = null;

        try{
            //HTTP Connection
//            URLConnection urlCon = new URL("http://premium.za.samsungmobile.com/samsung/servlet/XMLServlet/GetAllContentList?NUM=" + ILENG).openConnection();
            URLConnection urlCon = new URL("http://funclub.tr.samsungmobile.com/xml/sfc_home_xml.jsp?NUM=5").openConnection();

            bfrString = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "ISO-8859-1"));

            String line = "";
            Vector vtElem        = new Vector();
            Vector vRingtone     = new Vector();
            Vector vWallpapers   = new Vector();
            Vector vScreensavers = new Vector();
            Vector vGames        = new Vector();

            while ((line = bfrString.readLine()) != null)
            {
                sbfXml.append(line);
            }

            byte bxml[] = sbfXml.toString().getBytes("ISO-8859-1");
            ByteArrayInputStream is = new ByteArrayInputStream(bxml);

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(new InputSource(is));
            Element elem = doc.getDocumentElement();
            elem.normalize();

            nlTemp = elem.getChildNodes();

                for(int x=0;x<nlTemp.getLength();x++){
                    if(nlTemp.item(x).getChildNodes().getLength() > 0){
                        vtElem.addElement(nlTemp.item(x).getChildNodes());
                    }
                }
                
                for(int x=0;x<vtElem.size();x++){
                    Element tmpElem = (Element)vtElem.elementAt(x);
                    String strElem = tmpElem.getTagName();

                    for (int i = 0; i < ILENG; i++) {
                        Properties pptNode = new Properties();

                        nlTemp = tmpElem.getElementsByTagName("CONTENT_ID");
                        pptNode.setProperty("CONTENT_ID", nlTemp.item(i).getFirstChild().getNodeValue());
                        nlTemp = tmpElem.getElementsByTagName("CONTENT_NAME");
                        pptNode.setProperty("CONTENT_NAME", nlTemp.item(i).getFirstChild().getNodeValue());
                        nlTemp = tmpElem.getElementsByTagName("PREVIEW_URL");
                        pptNode.setProperty("PREVIEW_URL", nlTemp.item(i).getFirstChild().getNodeValue());

                        if(strElem.equals("GAMES")){
                            vGames.addElement(pptNode);
                        }
                        else if(strElem.equals("RINGTONES")){
                            vRingtone.addElement(pptNode);
                        }
                        else if(strElem.equals("WALLPAPERS")){
                            vWallpapers.addElement(pptNode);
                        }
                        else if(strElem.equals("SCREENSAVERS")){
                            vScreensavers.addElement(pptNode);
                        }
                  }
                }

            File fl = new File(FILE_PATH);

            if(!fl.isDirectory()){
                fl.mkdirs();
            }

            if(vRingtone.size() > 0){
                getRingtones(vRingtone);
            }

/*            if(vWallpapers.size() > 0){
                getWallpaper(vWallpapers);
            }*/

            if(vScreensavers.size() > 0){
                getScreensaver(vScreensavers);
            }

            if(vGames.size() > 0){
                getJavaGames(vGames);
            }
        }catch(Exception ex){
            ex.printStackTrace();
            Logger.getLogger("home.tur_home").info(ex.toString());
            ReportError.byEmail(MAILSUBJECT, ex.toString());
        }finally {
            if (bfrString != null) try { bfrString.close(); } catch (Exception e) {}
        }
    }


    //Make Ringtone File
    public void getRingtones(Vector pVector) throws Exception  {
        OutputStreamWriter fw = null;

        try{
            /* FUNCLUB MAIN RINGTONE*/
            sHtml.setLength(0);
            sHtml.append("<table width=200 cellpadding=0 cellspacing=0>\n")
                 .append("<form name=\"frm_list\" >\n")
                 .append("  <tr><td><img src=\""+IMAGE_URL_RINGTONE+"bg_box01_01.gif\"  align=absmiddle></td></tr>\n")
                 .append("  <tr>\n")
                 .append("      <td style=\"background-image : url("+IMAGE_URL_RINGTONE+"bg_box01_02.gif)\" align=center>\n")
                 .append("          <table width=174 cellpadding=0 cellspacing=0>\n")
                 .append("              <tr>\n")
                 .append("                  <td style=\"padding:0 0 2 0\"><img src=\""+IMAGE_URL_RINGTONE+"title_topseven.gif\"  align=absmiddle></td>\n")
                 .append("                  <td width=36><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=musictones&menu2=gercek\"><img src=\""+IMAGE_URL_RINGTONE+"bn_more01.gif\"  align=absmiddle></a></td>\n")
                 .append("              </tr>\n")
                 .append("              <tr><td height=1 bgcolor=#FF6F00 colspan=2></td></tr>\n")
                 .append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("  <tr>\n")
                 .append("      <td style=\"background-image : url("+IMAGE_URL_RINGTONE+"bg_box01_02.gif);padding:8 0 4 0 \" align=center class=fixed>\n")
                 .append("          <table width=174 cellpadding=0 cellspacing=0>\n")
                 .append("              <col width=148>\n")
                 .append("              <col width=26>\n");
            for(int i=0; i < pVector.size(); i++) {
                Properties pContentList = (Properties) pVector.elementAt(i);

                strContentID = StringUtils.defaultString(pContentList.getProperty("CONTENT_ID"),"");
                strContentName = StringUtils.defaultString(pContentList.getProperty("CONTENT_NAME"),"");

                if(strContentName.length() > 20){
                    strContentName = strContentName.substring(0, 20) + "..";
                }
                String strGB = "";
                if(i%2 != 0 )
                  strGB = "bgcolor=#EBEBEB";
                sHtml.append("              <tr height=32 "+strGB+">\n")
                     .append("                  <td class=p_0005><a href=\"http://funclub.tr.samsungmobile.com/sesler/index.jsp\"  class=f_11_00><b>"+strContentName+"</b></a></td>\n")
                     .append("                  <td>&nbsp;</td>\n")
                     .append("                <input type='hidden' name='title"+i+"' value='"+java.net.URLEncoder.encode(strContentName,"UTF-8")+"'> \n")
                     .append("                <input type='hidden' name='content_id"+i+"' value='"+strContentID+"'> \n")
                     .append("              </tr>\n");
            }
            sHtml.append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("  <tr><td><img src=\"/images/funclub/main/bg_box01_03.gif\"  align=absmiddle></td></tr>\n")
                 .append("</form>\n")
                 .append("</table>\n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/funclub_ringtone.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

            /* MAIN RINGTONE*/
            sHtml.setLength(0);
            sHtml.append("<table width=191 cellpadding=0 cellspacing=0>\n")
                 .append("<form name=\"frm_list\" >\n")
                 .append("    <tr>\n")
                 .append("        <td height=29 style='background-image : url(" + IMAGE_URL_MAIN + "bg_box02_01.gif)' align=center>\n")
                 .append("            <table width=170 cellpadding=0 cellspacing=0>\n")
                 .append("                <tr>\n")
                 .append("                    <td><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=musictones&menu2=gercek\"><img src='" + IMAGE_URL_MAIN + "title_ringtones.gif' align=absmiddle></a></td>    \n")
                 .append("                    <td width=36><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=musictones&menu2=gercek\"><img src='" + IMAGE_URL_MAIN + "bn_more01.gif' align=absmiddle></a></td> \n")
                 .append("                </tr>\n")
                 .append("            </table>\n")
                 .append("        </td> \n")
                 .append("    </tr>\n")
                 .append("    <tr>\n")
                 .append("        <td height=114 style='background-image : url(" + IMAGE_URL_MAIN + "bg_box02_02.gif);padding:5 0 0 0' align=center valign=top>  \n")
                 .append("            <table width=183 cellpadding=0 cellspacing=0>\n")
                 .append("                <col width=8>\n")
                 .append("                <col width=160>\n")
                 .append("                <col width=10>\n")
                 .append("                <col width=5>\n");

            if(pVector.size() >= 5) {
                for(int i=0; i < 5; i++) {
                    Properties pContentList = (Properties) pVector.elementAt(i);

                    strContentID = StringUtils.defaultString(pContentList.getProperty("CONTENT_ID"),"");
                    strContentName = StringUtils.defaultString(pContentList.getProperty("CONTENT_NAME"),"");
                    if(strContentName.length() > 20){
                        strContentName = strContentName.substring(0, 20) + "..";
                    }

                    sHtml.append("            <tr bgcolor=#F7FEFF> \n")
                         .append("                <td><img src='" + IMAGE_URL_MAIN + "bg_box02_03.gif' align=absmiddle></td> \n")
                         .append("                <td><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=musictones&menu2=gercek\" >" + (i+1) +". "+strContentName + "</a></td> \n")
                         .append("                <td>&nbsp;</td> \n")
                         .append("                <td align=right><img src='" + IMAGE_URL_MAIN + "bg_box02_04.gif' align=absmiddle></td> \n")
                         .append("                <input type='hidden' name='title"+i+"' value='"+java.net.URLEncoder.encode(strContentName,"UTF-8")+"'> \n")
                         .append("                <input type='hidden' name='content_id"+i+"' value='"+strContentID+"'> \n")
                         .append("            </tr> \n");
                    if ( i < 5 ) {
                        sHtml.append("        <tr><td colspan=4 height=1></td></tr>\n");
                    }
                }
            }

            sHtml.append("            </table>\n")
                 .append("        </td>\n")
                 .append("    </tr>\n")
                 .append("</form>\n")
                 .append("</table>\n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/ringtone_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();


        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }

    //Make Wallpaper File
    public void getScreensaver(Vector pVector) throws Exception {
        OutputStreamWriter fw = null;

        try{
            /* RINTONE MAIN SCREENSAVER*/
            sHtml.setLength(0);
            sHtml.append("<table width=200 cellpadding=0 cellspacing=0>\n")
                 .append("  <tr  height=39>\n")
                 .append("      <td style=\"background-image : url("+IMAGE_URL_IMAGE+"bg_box03_01.gif)\" align=center valign=bottom>\n")
                 .append("          <table width=174 cellpadding=0 cellspacing=0>\n")
                 .append("              <tr>\n")
                 .append("                  <td style=\"padding:0 0 6 0\"><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=graphics&menu2=screensavers\"><img src=\""+IMAGE_URL_IMAGE+"title_screensavers.gif\"  align=absmiddle></a></td>\n")
                 .append("                  <td width=36><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=graphics&menu2=screensavers\"><img src=\""+IMAGE_URL_IMAGE+"bn_more02.gif\"  align=absmiddle></a></td>\n")
                 .append("              </tr>\n")
                 .append("              <tr><td height=1 bgcolor=#C971AC colspan=2></td></tr>\n")
                 .append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("  <tr height=119 valign=top>\n")
                 .append("      <td style=\"background-image : url("+IMAGE_URL_IMAGE+"bg_box03_04.gif);padding:10 0 0 0\" align=center>\n")
                 .append("          <table cellpadding=0 cellspacing=0>\n")
                 .append("              <tr>\n");

            if(pVector.size() >= 2 ){
                for(int i=0 ; i<2 ; i++) {
                    Properties pContentList = (Properties) pVector.elementAt(i);

                    strContentName = StringUtils.defaultString(pContentList.getProperty("CONTENT_NAME"),"");
                    if(strContentName.length() > 10){
                        strContentName = strContentName.substring(0, 10) + "..";
                    }
                    strUrl = STR_URL+"menu1=graphics&menu2=screensavers&content_id="+pContentList.getProperty("CONTENT_ID");
                    strPreviewUrl = pContentList.getProperty("PREVIEW_URL");

                    sHtml.append("                  <td>\n")
                         .append("                      <table width=79 cellpadding=0 cellspacing=1>\n")
                         .append("                          <tr><td bgcolor=#9AA9B4><a href=\""+strUrl+"\"><img src=\""+strPreviewUrl+"\"  align=absmiddle width=77 height=77></a></td></tr>\n")
                         .append("                      <tr><td><img src=\""+IMAGE_URL_IMAGE+"icon_03.gif\" align=absmiddle>&nbsp;<a href=\""+strUrl+"\" class=f_11_ff>"+strContentName+"</a></td></tr>\n")
                         .append("                      </table>\n")
                         .append("                  </td>\n");
                    if(i == 0)
                      sHtml.append("                    <td width=8></td>\n");
                }
            }
            sHtml.append("              </tr>\n")
                 .append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("</table>\n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/funclub_image.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

            /* MAIN SCREENSAVER*/
            sHtml.setLength(0);
            sHtml.append("<table width=191 cellpadding=0 cellspacing=0>\n")
                 .append("  <tr height=29>\n")
                 .append("      <td style=\"background-image : url("+IMAGE_URL_MAIN+"bg_title_02.gif)\" align=center >\n")
                 .append("          <table width=170 cellpadding=0 cellspacing=0>\n")
                 .append("              <tr>\n")
                 .append("                  <td><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=graphics&menu2=screensavers\"><img src=\""+IMAGE_URL_MAIN+"title_screensavers.gif\"  align=absmiddle></a></td>\n")
                 .append("                  <td width=36><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=graphics&menu2=screensavers\"><img src=\""+IMAGE_URL_MAIN+"bn_more03.gif\"  align=absmiddle></a></td>\n")
                 .append("              </tr>\n")
                 .append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("  <tr><td height=2><!-- blank --></td></tr>\n")
                 .append("  <tr>\n")
                 .append("      <td height=112 style=\"background-image : url("+IMAGE_URL_MAIN+"bg_box03.gif);padding:13 0 0 0\" align=center valign=top>\n")
                 .append("          <table width=166 cellpadding=0 cellspacing=0>\n")
                 .append("              <tr>\n");
            if(pVector.size() >= 2 ){
                for(int i=0 ; i<2 ; i++) {
                    Properties pContentList = (Properties) pVector.elementAt(i);

                    strContentName = StringUtils.defaultString(pContentList.getProperty("CONTENT_NAME"),"");
                    if(strContentName.length() > 12){
                        strContentName = strContentName.substring(0, 12) + "..";
                    }
                    strUrl = STR_URL+"menu1=graphics&menu2=screensavers&content_id="+pContentList.getProperty("CONTENT_ID");
                    strPreviewUrl = pContentList.getProperty("PREVIEW_URL");

                    sHtml.append("                  <td>\n")
                         .append("                      <table width=79 height=79 cellpadding=1 cellspacing=0>\n")
                         .append("                          <tr><td bgcolor=#9AA9B4><a href=\""+strUrl+"\"><img src=\""+strPreviewUrl+"\" width=77 height=77></a></td></tr>\n")
                         .append("                          <tr><td class=f_09 style=\"padding:3 0 0 0\"><img src=\""+IMAGE_URL_MAIN+"icon_02.gif\"align=absmiddle>&nbsp;<a href="+strUrl+">"+strContentName+"</a></td></tr>\n")
                         .append("                      </table>\n")
                         .append("                  </td>\n");
                    if(i == 0)
                      sHtml.append("                    <td width=8></td>\n");
                }
            }
            sHtml.append("              </tr>\n")
                 .append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("</table>\n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/image_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();
        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }


    //Make JavaGames File
    public void getJavaGames(Vector pVector) throws Exception {
        OutputStreamWriter fw = null;

        try{
            /* FUNCLUB MAIN GAME*/
            sHtml.setLength(0);
            sHtml.append("<table width=500 cellpadding=0 cellspacing=0>\n")
                 .append("  <tr  height=39>\n")
                 .append("      <td style=\"background-image : url("+IMAGE_URL_GAME+"bg_box06_01.gif)\" align=center valign=bottom>\n")
                 .append("          <table width=480 cellpadding=0 cellspacing=0>\n")
                 .append("              <tr>\n")
                 .append("                  <td style=\"padding:0 0 6 7\"><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=games\"><img src=\""+IMAGE_URL_GAME+"title_mobile_games.gif\"  align=absmiddle></a></td>\n")
                 .append("                  <td width=36><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=games\"><img src=\""+IMAGE_URL_GAME+"bn_more06.gif\"  align=absmiddle></a></td>\n")
                 .append("              </tr>\n")
                 .append("              <tr><td height=1 bgcolor=#49A8D9 colspan=2></td></tr>\n")
                 .append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("  <tr height=119>\n")
                 .append("      <td style=\"background-image : url("+IMAGE_URL_GAME+"bg_box06_02.gif);padding:10 0 0 0\" align=center valign=top>\n")
                 .append("          <table width=480 cellpadding=0 cellspacing=0>\n")
                 .append("              <tr>\n")
                 .append("                  <td width=203 valign=top align=center>\n");
            if(pVector.size() > 0) {
                Properties pContentList = (Properties) pVector.elementAt(0);

                strContentName = StringUtils.defaultString(pContentList.getProperty("CONTENT_NAME"),"");

                strUrl = STR_URL+"menu1=games&menu2=mobile&content_id="+pContentList.getProperty("CONTENT_ID");
                strPreviewUrl = pContentList.getProperty("PREVIEW_URL");

                sHtml.append("                      <table width=190 cellpadding=0 cellspacing=0>\n")
                     .append("                          <tr>\n")
                     .append("                              <td>\n")
                     .append("                                  <table width=79 height=79 cellpadding=0 cellspacing=1 bgcolor=#9D9D9D>\n")
                     .append("                                      <tr><td><a href=\""+strUrl+"\"><img src=\""+strPreviewUrl+"\"  width=77 height=77  align=absmiddle></a></td></tr>\n")
                     .append("                                  </table>\n")
                     .append("                              </td>\n")
                     .append("                              <td style=\"padding:0 0 0 10\">\n")
                     .append("                                  <a href=\""+strUrl+"\" class=f_11_ff ><b>"+strContentName+"</b></a>\n")
                     .append("                              </td>\n")
                     .append("                          </tr>\n")
                     .append("                      </table>\n");
            }
            sHtml.append("                  </td>\n")
                 .append("                  <td style=\"padding:10 0 0 0\" valign=top  align=center >\n")
                 .append("                      <table width=250 cellpadding=0 cellspacing=0>\n")
                 .append("                          <tr>\n");
            if(pVector.size() >= 5) {
              for(int i=1; i<5; i++){
                Properties pContentList = (Properties) pVector.elementAt(i);

                strContentName = StringUtils.defaultString(pContentList.getProperty("CONTENT_NAME"),"");
                if(strContentName.length() > 8){
                    strContentName = strContentName.substring(0, 7) + "..";
                }
                strUrl =STR_URL +"menu1=games&menu2=mobile&content_id="+pContentList.getProperty("CONTENT_ID");
                strPreviewUrl = pContentList.getProperty("PREVIEW_URL");
                sHtml.append("                              <td>\n")
                     .append("                                  <table width=58 height=54 cellpadding=0 cellspacing=1>\n")
                     .append("                                      <tr><td bgcolor=#9D9D9D><a href=\""+strUrl+"\"><img src=\""+strPreviewUrl+"\" width=56 height=52 align=absmiddle></a></td></tr>\n")
                     .append("                                      <tr><td valign=bottom class=f_09><img src=\""+IMAGE_URL_GAME+"icon_06.gif\" align=absmiddle>&nbsp;<a href=\""+strUrl+"\">"+strContentName+"</a></td></tr>\n")
                     .append("                                  </table>\n")
                     .append("                              </td>\n");
                if(i != 4)
                  sHtml.append("                                <td width=6><!-- blank --></td>\n");
              }
            }
            sHtml.append("                          </tr>\n")
                 .append("                      </table>\n")
                 .append("                  </td>\n")
                 .append("              </tr>\n")
                 .append("          </table>\n")
                 .append("      </td>\n")
                 .append("  </tr>\n")
                 .append("</table>\n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH+"/funclub_game.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

            /* MAIN GAME*/
            sHtml.setLength(0);
            sHtml.append("<table width=191 cellpadding=0 cellspacing=0>\n")
                 .append("<tr height=29>\n")
                 .append("  <td style=\"background-image : url("+IMAGE_URL_MAIN+"bg_title_01.gif)\" align=center >\n")
                 .append("      <table width=170 cellpadding=0 cellspacing=0>\n")
                 .append("          <tr>\n")
                 .append("              <td><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=games\"><img src=\""+IMAGE_URL_MAIN+"title_mobile_games.gif\"  align=absmiddle></a></td>\n")
                 .append("              <td width=36><a href=\"http://www.samsungmobile.com.tr/link/goPremium.jsp?menu1=games\"><img src=\""+IMAGE_URL_MAIN+"bn_more02.gif\"  align=absmiddle></a></td>\n")
                 .append("          </tr>\n")
                 .append("      </table>\n")
                 .append("  </td>\n")
                 .append("</tr>\n")
                 .append("<tr><td height=2><!-- blank --></td></tr>\n")
                 .append("<tr>\n")
                 .append("  <td height=112 style=\"background-image : url("+IMAGE_URL_MAIN+"bg_box03.gif);padding:13 0 0 0\" align=center valign=top>\n")
                 .append("      <table width=166 cellpadding=0 cellspacing=0>\n")
                 .append("          <tr>\n");
            if(pVector.size() >= 2) {
              for(int i=0; i<2; i++){
                Properties pContentList = (Properties) pVector.elementAt(i);

                strContentName = StringUtils.defaultString(pContentList.getProperty("CONTENT_NAME"),"");
                if(strContentName.length() > 12){
                    strContentName = strContentName.substring(0, 12) + "..";
                }
                strUrl = STR_URL+"menu1=games&menu2=mobile&content_id="+pContentList.getProperty("CONTENT_ID");
                strPreviewUrl = pContentList.getProperty("PREVIEW_URL");

                sHtml.append("              <td>\n")
                     .append("                  <table width=79 height=79 cellpadding=1 cellspacing=0>\n")
                     .append("                      <tr><td  bgcolor=#9AA9B4><a href="+strUrl+"><img src=\""+strPreviewUrl+"\" width=77 height=77 align=absmiddle></a></td></tr>\n")
                     .append("                      <tr><td class=f_09 style=\"padding:3 0 0 0\"><img src=\""+IMAGE_URL_MAIN+"icon_02.gif\"align=absmiddle>&nbsp;<a href="+strUrl+">"+strContentName+"</a></td></tr>\n")
                     .append("                  </table>\n")
                     .append("              </td>\n");
                if(i != 1)
                  sHtml.append("                <td width=8></td>\n");
              }
            }
            sHtml.append("          </tr>\n")
                 .append("      </table>\n")
                 .append("  </td>\n")
                 .append("</tr>\n")
                 .append("</table>\n");

            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH+ "/javagame_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();
        }
        finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }

    public static void main( String[] args ){
      Logger.getLogger("home.tur_home").info("( * ) Start.");
      makeHomeForTur mvm = new makeHomeForTur();
      Logger.getLogger("home.tur_home").info("( * ) End.");
    }
}